package com.hansming.bss.modules.sfc.controller;

import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.activiti.engine.impl.util.json.JSONArray;
import org.activiti.engine.impl.util.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hansming.bss.common.web.BaseController;
import com.hansming.bss.modules.sfc.entity.WxUser;
import com.hansming.bss.modules.sfc.service.WxUserService;
import com.hansming.bss.modules.sfc.util.MiniAppHelp;

@Controller
@RequestMapping(value = "/usertest")
public class PcTestController extends BaseController{
	
	@Autowired
	private WxUserService wxuserservice;
	
	
	@RequestMapping(value="")
	public void test(HttpServletRequest request, HttpServletResponse response,String usercode){
		response.setCharacterEncoding("UTF-8");
		response.setHeader("Access-Control-Allow-Origin", "*");
        response.setHeader("Cache-Control", "no-cache");  
        System.out.println("进入测试方法=-=-=-="+"code:"+usercode);
        try{
        	//信息传递标头
        	JSONArray datas = new JSONArray();		//返回到前台的具体的价格日期信息json
    		String code = "1";								//返回前台的消息状态
    		String msg = "传递成功";	
    		JSONObject jsonObject = new JSONObject(); 
			PrintWriter out = response.getWriter();   
			if(!usercode.equals("")){
			JSONObject obj = MiniAppHelp.oauth2GetOpenid(usercode);
				String openid = obj.getString("openid");
				String sessionkey = obj.getString("session_key");
				String unionid 	= obj.getString("unionid");
				WxUser wxuser = wxuserservice.getWxUserByOpenid(openid);
				System.out.println("openid:"+openid+"----session_key:"+sessionkey+"-----unionid:"+unionid);
			}
			jsonObject.put("code",code);
			jsonObject.put("msg", msg);
			jsonObject.put("data",datas);
			out.print(jsonObject.toString());
			out.flush();
			out.close();
        }catch(Exception e){
        	
        }
	}
	
}
